package org.smartboot.flow.core.builder;

import org.smartboot.flow.core.Adapter;
import org.smartboot.flow.core.attribute.Attributes;
import org.smartboot.flow.core.component.AdapterComponent;
import org.smartboot.flow.core.component.Component;

/**
 * @author huqiang
 * @since 2022/12/7 19:36
 */
public class AdapterBuilder<T,S, P, Q> extends ExecutableBuilder<T,S> {

    private final Adapter<T,S, P, Q> adapter;

    private final Component<P, Q> component;

    public AdapterBuilder(Adapter<T,S, P, Q> adapter, Component<P, Q> component) {
        this.adapter = adapter;
        this.component = component;
    }

    public AdapterComponent<T, S, P, Q> build() {
        AdapterComponent<T, S, P, Q> adapterComponent = new AdapterComponent<>();
        adapterComponent.setAdapter(adapter);
        adapterComponent.setComponent(component);
        applyValues(adapterComponent);
        return adapterComponent;
    }

    /**
     * Resolve return type.
     */
    public AdapterBuilder<T, S, P, Q> apply(Attributes attributes, Object value) {
        super.apply(attributes, value);
        return this;
    }

}
